/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.rm.beans.converters;

import javax.el.ELContext;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.rm.beans.FormularioBean;
import org.rm.entidades.Jugador;

/**
 *
 * @author ffbeltran
 */
public class JugadoresConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        FormularioBean form = (FormularioBean) FacesContext.getCurrentInstance().getApplication()
        .getELResolver().getValue(elContext, null, "form");
        Integer idJugador = Integer.parseInt(value);
        return form.getJugador(idJugador);
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value instanceof Jugador)
            return ((Jugador) value).getId().toString();
        return "";
    }

}
